package com.young.coderule.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.young.coderule.common.dto.BaseResult;
import com.young.coderule.entity.ComCodeRule;
import com.young.coderule.entity.ComCodeRuleNumber;
import com.young.coderule.service.ComCodeRuleNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * @DESCRIPTION: 最大流水号表控制器
 * @USER: Young
 */
@RequestMapping("/comCodeRuleNumber")
@RestController
public class ComCodeRuleNumberController {

    @Autowired
    private ComCodeRuleNumberService comCodeRuleNumberService;

    @PostMapping()
    public BaseResult add(@RequestBody @Validated(ComCodeRuleNumber.class) ComCodeRuleNumber comCodeRuleNumber) {
        comCodeRuleNumberService.add(comCodeRuleNumber);
        return BaseResult.success("添加成功");
    }

    @DeleteMapping("/{id}")
    public BaseResult delete(@PathVariable("id") Serializable id) {
        comCodeRuleNumberService.removeById(id);
        return BaseResult.success("删除成功");
    }

    @PutMapping
    public BaseResult edit(@RequestBody @Validated(ComCodeRuleNumber.class) ComCodeRuleNumber comCodeRuleNumber) {
        comCodeRuleNumberService.edit(comCodeRuleNumber);
        return BaseResult.success("修改成功");
    }

    @GetMapping("/{id}")
    public BaseResult detail(@PathVariable("id") Serializable id) {
        return BaseResult.success("获取详情成功", comCodeRuleNumberService.getById(id));
    }

    @GetMapping("/list")
    public BaseResult list() {
        return BaseResult.success("获取列表成功",comCodeRuleNumberService.list());
    }

    @PostMapping("/page")
    public BaseResult page(@RequestBody ComCodeRule comCodeRule, Page page) {
        QueryWrapper queryWrapper = new QueryWrapper(comCodeRule);
        IPage<ComCodeRule> comCodeRules = comCodeRuleNumberService.page(page, queryWrapper);
        return BaseResult.success("分页查询成功", comCodeRules);
    }

}